package com.feel.modules.auth.service.impl;

import cn.dev33.satoken.oauth2.logic.SaOAuth2Template;
import cn.dev33.satoken.oauth2.model.SaClientModel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feel.modules.auth.entity.OauthClientDetailsEntity;
import com.feel.modules.auth.service.OauthClientDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SaOAuth2ServiceImpl extends SaOAuth2Template {


    @Autowired
    private OauthClientDetailsService saClientService;

    /**
     * // 根据 id 获取 Client 信息
     *
     * @param clientId
     * @return
     */
    @Override
    public SaClientModel getClientModel(String clientId) {
        QueryWrapper<OauthClientDetailsEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("client_id", clientId);
        OauthClientDetailsEntity oauthclient = saClientService.getOne(wrapper);
        if (null != oauthclient) {
            return new SaClientModel()
                    .setClientId(oauthclient.getClientId())
                    .setClientSecret(oauthclient.getClientSecret())
//                     .setAllowUrl(oauthclient.getAllowUrl())
                    .setContractScope(oauthclient.getScope());
        }
        return null;
    }


    /**
     *  // 根据ClientId 和 LoginId 获取openid
     * @param clientId
     * @param loginId
     * @return
     */
    @Override
    public String getOpenid(String clientId, Object loginId) {
        return super.getOpenid(clientId, loginId);
    }
}
